package com.example.demo.util;

import com.sun.istack.internal.logging.Logger;

import java.util.Properties;

/**
 * Created by Hy on 2018/8/6.
 */
public class SendEmail {
    private static final Logger logger = Logger.getLogger(SendEmail.class);
    private String host = "";//smtp服务器
    private String from = "";//发件人地址
    private String to = "";//收件人地址
    private String[] attachmentPath = null; // 附件地址
    private String user = ""; // 用户名
    private String pwd = ""; // 密码
    private String subject = ""; // 邮件标题
    private int status = 0; // 发送结果：0-成功，1-失败
    private String htmlContent = ""; //若果发送的是html格式的邮件，这是html内容

    public void setAddress(String from,String to,String subject){
        this.from = from;
        this.to = to;
        this.subject = subject;
    }

    public void setAttachmentPath(String[] attachmentPath) {
        this.attachmentPath = attachmentPath;
    }

    public void setHtmlContent(String htmlContent) {
        this.htmlContent = htmlContent;
    }

    public int sendMail(String user,String pwd,String host){
        //1.创建参数配置，用于连接邮件服务器的参数配置
        Properties prop = new Properties();
        prop.put("mail.smtp.host",host);
        prop.put("mail.smtp.auth","true");
        prop.put("mail.smtp.port","25");
        prop.put("mail.transport.protocol","smtp");

        //2.根据配置创建会话对象，用于和邮件服务器交互
        //Session.getInstance(prop);
        return 0;
    }
}
